home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 19 / Mac Magazin and MacEasy Magazine CD - Issue 19.iso / Online / LineShare 3.3.1 / LineShare Scripts / USR Courier Fax1&ARA&Data < prev    next >
Text File  |  1994-09-13  |  8KB  |  374 lines

  1. ! Version 3.0
  2. !
  3. !$ Use this script with USRobotics Courier data/fax modems.
  4. !$ Supports: fax, ARA and regular data incoming calls.
  5. !
  6. !$ Make sure that *Class 1* fax software is installed
  7. !
  8.  
  9. ^2 Speaker On:        = Enum("Never" = "0","During Connect" = "1", "Always"="2") "1"
  10. ^3 Speaker Volume:       = Enum("Low"="1","Medium"="2","High"="3") "2"
  11. ^4 Answer On:         = Enum("1 Ring"="1","2 Rings"="2","3 Rings"="3","5 Rings"="5","7 Rings"="7") "2"
  12. ^5 Port Speed:        = Enum("9600","19200","38400","57600") "19200"
  13. ^6 Handshake wires:   = Bool("Both"="&D0","CTS only"="&D2") "&D2"
  14. ! ------------------------------------------
  15. ! Resetting the modem:
  16. ! ------------------------------------------
  17. @Hangup
  18.   SetTries 2
  19.   Flush
  20.   HsReset 0,0,0,0,0,0
  21.   DtrSet
  22. !
  23. ! Try to catch the "OK" answer, use the Escape seq and DTR transitions
  24. ! to enter the command mode
  25. !
  26. @Label 1
  27.   matchclr
  28.   matchstr 1 2 "OK\r\n"
  29.   write "ATV1H0&F1\r"
  30.   matchread 20
  31.   ChrDelay 1
  32.   Write "+++"
  33.   ChrDelay 0
  34.   DtrClear
  35.   SBreak
  36.   DtrSet
  37. !
  38.   DecTries
  39.   IfTries 0 1
  40. !
  41. ! OSErr -6019 "Modem error - the modem is not responding"
  42. !
  43.   exit -6019
  44. @Label 2
  45.   write "AT+FCLASS=0\r"
  46.   Jsr 100
  47.   exit 0
  48.  
  49. ! ------------------------------------------
  50. !    Receiving incoming calls
  51. ! ------------------------------------------
  52. @ANSWER
  53. !
  54. ! Set the modem preferred speed first
  55. !
  56.   SerReset Val("^5"),0,8,1
  57.   Jsr 80
  58.  
  59. @Label 10
  60. !
  61. ! Set the common options
  62.   Jsr 70
  63. !
  64. ! Set Fax mode
  65. !
  66.   Write "AT+FCLASS=1\r"
  67.   Jsr 100
  68.   Write "AT+FAA=1\r"
  69.   Jsr 100
  70. !
  71.   Write "AT&M0&H2&R1&I2S13=1\r"
  72.   Jsr 100
  73. !
  74. ! Tell the modem to determine the type of the incoming call
  75. ! Fetch the tube after ^4 rings
  76. !
  77.   Write "ATS0=^4V0\r"
  78.   Jsr 110
  79. !
  80. ! Everything is ready - let's sit and wait for a call
  81. ! We'll wait for 2 minutes, then reinitiate the modem
  82. !
  83.   Note "Waiting for a fax/ARA/data call…"
  84.   MatchClr
  85.   Matchstr 01 13 "2\r"
  86.   MatchStr 02 14 "64\r"
  87.   MatchStr 03 15 "63\r"
  88.   Matchstr 04 57 "1\r"
  89.   Matchstr 11 12 "3\r"
  90.   Matchstr 12 12 "8\r"
  91.   Matchstr 13 12 "7\r"
  92. @Label 11
  93.   Matchread 1200
  94. @Label 12
  95.   Note "Tuning again…"
  96.   Write "ATV1\r"
  97.   Jsr 100
  98.   Jump 10
  99. @Label 13
  100.   Note "Ring…"
  101.   jump 11
  102. @Label 14
  103. ! SetSpeed 19200
  104.   Note "Fax tones detected…"
  105.   Jump 11
  106.  
  107. !
  108. ! Data connection established: sitch to verbos and go on-line
  109. !
  110. @Label 15
  111.   Note "Data connection…"
  112. !
  113. ! Set the communication options:
  114. ! • &M0,&B1: Normal connection (for ARA)
  115. ! • &H1 &R1: HW out flow control, no in flow control (for ARA, Fax should not use a handshake on receiving)
  116. ! • &A1:  report connection speed
  117.   Write "AT&H1&R1&I0&A1V1&B1O0\r"
  118.   MatchClr
  119.   MatchStr 01 16 "CONNECT ^$/"
  120.   MatchStr 02 16 "CONNECT ^$\r\n"
  121.   MatchStr 10 10 "NO CARRIER\r\n"
  122.   MatchStr 11 10 "NO ANSWER\r\n"
  123.   MatchRead 100
  124.   Jump 10
  125.  
  126. @Label 16
  127.   SetVar B "^$"
  128. !
  129. ! Data connection has been established (we read "CONNECT")
  130. ! Put the "CONNECT" back to the buffer and attach the "Data" subPort
  131. ! if it was an incoming call, put the "RING" before the "CONNECT"
  132. !
  133. @Label 20
  134.   IfOpen "Data" 21
  135.   Jump 30
  136. @Label 21
  137.   IfOpen "ARA" 22
  138.   Jump 35
  139. @Label 22
  140.   Note "Waiting for an ARA frame"
  141.   MatchClr
  142.   MatchStr 1 23 "^$\r"
  143.   MatchStr 2 28 "\08\01\03\14\04\03\00\08\250\16\03"
  144.   MatchStr 3 29 "\01\27\02\29\01\02\01\06"
  145.   MatchRead 60
  146.   Jump 24
  147. @Label 23
  148.   QueueInput "^$\r"
  149. @Label 24
  150.   Note "Non-ARA call"
  151.   Jump 35
  152.  
  153. @Label 28
  154.   Note "ARA 1.0 call"
  155.   Jump 30
  156. @Label 29
  157.   Note "ARA 2.0 call"
  158.   Jump 30
  159.  
  160. @Label 30
  161.   QueueInput "\r\nCARRIER ^B\r\n"  
  162.   QueueInput "\r\nRING\r\n"
  163.   Attach "ARA" (DTR)
  164.  
  165. @Label 35
  166.   GetSReg C "DATA" 4
  167.   QueueInput "\r^CCONNECT ^B\r^C"
  168.   ifOriginate 36
  169.   QueueInput "\r^CRING\r^C"
  170. @Label 36
  171.   Attach "Data" (DTR,Escape,Break)
  172.  
  173.  
  174. ! ------------------------------------------
  175. ! Originating a call through the "ARA" subport
  176. ! ------------------------------------------
  177. @ORIGINATE "ARA"
  178.   SerReset Val("^5"),0,8,1
  179.   Jsr 80
  180. !
  181. ! Set the common options
  182. !
  183.   Jsr 70
  184. !
  185. ! Set the Data mode:
  186. ! • &M0,&B1:Normal connection (no compression, correction - for ARA)
  187. ! • &H1,&R1: HW Handshake
  188. ! • S7:  time-out (90 sec) for long-distance call (if you use them)
  189. ! • &A1:  report connection rate
  190. !
  191.   Write "AT&H1&R1&I0S7=90&A1&M0&B1\r"
  192.   Jsr 100
  193. !
  194. ! Emit the ARA script commands ("Xnn")
  195.   Jsr 60
  196. !
  197. ! Prepare to receive all error result codes, dial the number
  198. !
  199.   Jsr 90
  200.   MatchStr 10 55 "\r\nCONNECT ^$/"
  201.   MatchStr 11 55 "\r\nCONNECT ^$\r\n"
  202.   MatchRead 1000
  203.   Write "\r"
  204.   Exit -6019
  205. @Label 55
  206.   QueueInput "\r\nCARRIER ^$\r\n"
  207.   Attach "ARA" (DTR)
  208.  
  209. ! ------------------------------------------
  210. ! Originating a call through the "DATA" subport
  211. ! ------------------------------------------
  212. @ORIGINATE "Data"
  213.   SerReset Val("^5"),0,8,1
  214.   Jsr 80
  215. !
  216. ! Set the common options
  217. !
  218.   Jsr 70
  219. !
  220. ! Emit the Data commands
  221.   Jsr 60
  222. !
  223. ! Set the Data mode:
  224. ! • &M4,&B1: Auto-reliable
  225. ! • &H1,&R1: HW Handshake
  226. ! • S7:  time-out (90 sec) for long-distance call (if you use them)
  227. ! • &A1: ARQ codes
  228. !
  229.   Write "AT&M4&B1&H1&R1&I0S7=90\r"
  230.   Jsr 100
  231. !
  232. ! Prepare to receive all error result codes, dial the number
  233. !
  234.   Jsr 90
  235.   MatchStr 10 56 "\r\nCONNECT "
  236.   MatchRead 1000
  237.   Write "\r"
  238.   Exit -6019
  239. @Label 56
  240.   QueueInput "\r\nCONNECT "
  241.   Attach "Data" (DTR,Escape,Break)
  242.  
  243. ! ------------------------------------------
  244. ! Originating a call through the "Fax" subPort
  245. ! ------------------------------------------
  246. @ORIGINATE "Fax"
  247. !
  248. ! Set the "Fax" speed
  249. !
  250.   SerReset 19200,0,8,1
  251.   Jsr 80
  252. !
  253. ! Set the common options
  254. !
  255.   Jsr 70
  256. !
  257. ! Set the Fax mode
  258. ! &H2: Xon/Xoff handshake
  259. !
  260.   Write "AT&R1&H2+FCLASS=1\r"
  261.   Jsr 100
  262. !
  263. ! Now emit all commands that the application has sent to that port,
  264. ! except "FCLASS", etc
  265. !
  266.   EmitClear "+FCLASS","V","E"
  267.   Jsr 60
  268.   Write "ATV0\r"
  269.   Jsr 110
  270. !
  271. ! Prepare to receive all error result codes, dial the number
  272. !
  273.   MatchClr
  274.   MatchStr 01 57 "1\r"
  275.   MatchStr 13 93 "3\r"
  276.   MatchStr 14 94 "8\r"
  277.   MatchStr 15 92 "7\r"
  278.   Write "ATD^1\r"
  279.   HsReset *
  280.   MatchRead 900
  281.   Write "\r"
  282.   Exit -6019
  283.  
  284. !
  285. ! Fax connection has been established (we read "FAX")
  286. ! Put the "CONNECT" ("1\r") back to the buffer,
  287. ! if it was an incoming call, put the "RING" ("2\r") before the "CONNECT"
  288. ! Attach the "Fax" subPort
  289. !
  290. @Label 57
  291.   QueueInput "1\r"
  292.   SetSpeed 19200
  293.   ifOriginate 59
  294. !@Label 58
  295.   QueueInput "2\r2\r"
  296. @Label 59
  297.   Attach "Fax" (Reset(2400),IdleLimit=30)
  298.  
  299. !
  300. ! This section emits all modem commands sent from the client application
  301. ! For each set of commands the "OK" answer is awaited
  302. !
  303. @Label 60
  304.   EmitStart
  305. @Label 61
  306.   EmitCommand 62
  307.   Jsr 100
  308.   Jump 61
  309. @Label 62
  310.   return
  311. !
  312. ! This section initiates the modem before ANSWER and ORIGINATEs:
  313. ! extended responses + connect at the highest rate + speaker control +
  314. ! reset on Dtr drop + DCD valid
  315. ! Verbal responses mode, no echo 
  316. !
  317. @Label 70
  318.   Write "ATX4M^2L^3^6&C1V1E0\r"
  319.   Jsr 100
  320.   return 
  321.  
  322. !
  323. ! This section syncronize the modem after the serial port speed switching
  324. !
  325. @Label 80
  326.   ChrDelay 1
  327.   Write "AT\r"
  328.   ChrDelay 0
  329.   Jsr 100
  330.   return
  331. !
  332. ! Prepare to receive error result codes, send the dialing command and
  333. ! set the user's handshake mode
  334. !
  335. @Label 90
  336.   MatchClr
  337.   MatchStr 2 91 "NO DIALTONE\r\n"
  338.   MatchStr 3 92 "BUSY\r\n"
  339.   MatchStr 4 93 "NO CARRIER\r\n"
  340.   MatchStr 5 94 "NO ANSWER\r\n"
  341.   Write "ATD^1\r"
  342.   HsReset *
  343.   return
  344. @Label 91
  345.   exit -6020
  346. @Label 92
  347.   exit -6022
  348. @Label 93
  349.   exit -6021
  350. @Label 94
  351.   exit -6023
  352. !
  353. ! Processing the AT command:
  354. ! OK -> proceed
  355. ! ERROR or TimeOut ->exit -6019
  356. ! It can be called AFTER the "Write" command, since LineShare buffers input
  357. !
  358. @Label 100
  359.   MatchClr
  360.   MatchStr 1 103 "\r\nOK\r\n"
  361.   MatchStr 2 102 "\r\nERROR\r\n"
  362. @Label 101
  363.   MatchRead 20
  364. @Label 102
  365.   Exit -6019
  366. @Label 103
  367.   return
  368.  
  369. @Label 110
  370.   MatchClr
  371.   MatchStr 1 103 "0\r"
  372.   MatchStr 2 102 "4\r"
  373.   Jump 101
  374.